<template>
  <!-- 主体部分 -->
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../../assets/img/heima.png" alt="" />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="loginOut" class="loginOut">退出</el-button>
    </el-header>
    <!-- 中心和侧边栏 -->
    <el-container>
      <!-- 侧边栏 -->
      <home-side :menuList="menuList" :iconsObj="iconsObj" />
      <!-- 中心区域 -->
      <el-main><router-view /></el-main>
    </el-container>
  </el-container>
</template>

<script>
import HomeSide from './childComps/HomeSide.vue'
export default {
  components: { HomeSide },
  name: 'Home',
  data() {
    return {
      menuList: [],
      iconsObj: {
        125: 'iconfont icon-users',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao',
      },
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    loginOut() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    //获取侧边菜单数据
    async getMenuList() {
      //解构
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      } else {
        this.menuList = res.data
      }
    },
  },
}
</script>

<style lang="less" scoped>
.home-container {
  // width: 1280px;
  height: 100%;
  margin: 0 auto;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #343b3e;
  padding-right: 50px;
  div {
    line-height: 60px;
    img {
      vertical-align: middle;
    }
    span {
      font-size: 20px;
      color: #fff;
      padding-left: 10px;
    }
  }
  .loginOut {
    padding: 0;
    height: 40px;
    width: 70px;
  }
}
.el-main {
  background-color: #e9edf1;
}
</style>